/**
 * Created by zhouli on 18/6/21
 * Email li.zhou@huilianyi.com
 */
import React from 'react';
import {connect} from 'react-redux';
import { Icon } from "antd";
import {messages} from "share/common";

import 'styles/components/template/reset-password/password-rule.scss';

class PasswordRule extends React.Component {
  constructor(props) {
    super(props);
  }
  componentWillMount() {

  }
  //密码长度
  renderLength = () => {
    let passwordRule = this.props.rule;
    if (passwordRule.minLength == passwordRule.maxLength) {
      return (
        <span>
          <span>
            {messages('components.key508'/*长度为*/)}
          </span>
          <span>&nbsp;{passwordRule.maxLength}&nbsp;</span>
        </span>
      )
    } else {
      return (
        <span>
          <span>
            {messages('components.key508'/*长度为*/)}
          </span>
          <span>&nbsp;{passwordRule.minLength}&nbsp;</span>
           <span>
             {messages('components.key509'/*至*/)}
           </span>
          <span>&nbsp;{passwordRule.maxLength}&nbsp;</span>
        </span>
      )
    }
  }
  //是否需要数字
  renderNeedNumber = () => {
    let passwordRule = this.props.rule;
    if (passwordRule.isNeedNumber) {
      return (
        <span>
          <span>,</span>
          <span>
            {messages('components.key510'/*必须包含数字*/)}
          </span>
        </span>
      )
    }

  }
  //是否需要小写字母
  renderNeedLowercase = () => {
    let passwordRule = this.props.rule;
    if (passwordRule.isNeedLowercase) {
      return (
        <span>
          <span>,</span>
          <span>
            {messages('components.key511'/*必须包含小写字母*/)}
          </span>
        </span>
      )
    }
  }

  //是否需要大写字母
  renderNeedUppercase = () => {
    let passwordRule = this.props.rule;
    if (passwordRule.isNeedUppercase) {
      return (
        <span>
          <span>,</span>
          <span>
            {messages('components.key512'/*必须包含大写字母*/)}
          </span>
        </span>
      )
    }
  }
  //是否需要特殊字符
  renderNeedSpecialChar = () => {
    let passwordRule = this.props.rule;
    if (passwordRule.isNeedSpecialChar) {
      return (
        <span>
          <span>,</span>
          <span>
            {messages('components.key513'/*必须包含特殊字符*/)}
          </span>
        </span>
      )
    }
  }

  render() {
    return (
      <div className="password-rule-wrap">
        <div className="password-rule">
          <span>
            {messages('components.key514'/*新密码规则:*/)}
          </span>
          {this.renderLength()}
          {this.renderNeedNumber()}
          {this.renderNeedLowercase()}
          {this.renderNeedUppercase()}
          {this.renderNeedSpecialChar()}
        </div>
      </div>
    );
  }
}

PasswordRule.propTypes = {
  rule: React.PropTypes.any,//传入的密码规则
};

PasswordRule.contextTypes = {
  router: React.PropTypes.object
};
PasswordRule.defaultProps = {};

function mapStateToProps(state) {
  return {
    profile: state.login.profile,
    user: state.login.user,
    tenantMode: state.main.tenantMode,
    company: state.login.company,
  }
}

export default connect(mapStateToProps)(PasswordRule);



